import { Asset, JsonAsset } from "cc";
import { tb_container, tb_decoder } from "../../platform/excel_table/ExcelConfigDecorator";
import { ITbDecode } from "../../platform/excel_table/ITbDecode";
import { TbContainer } from "../../platform/excel_table/TbContainer";
import { GameCtx } from "../GameCtx";
import { Platform } from "../common/enums";
import { ResManager } from "../../platform/resources/ResMgr";

export class Tb_GameList {
    id: number
    name:string
    icon:string
    levels:number[]
    show:boolean
    sort:number
}

@tb_container(Tb_GameList)
export class Tb_GameListContainer extends TbContainer<Tb_GameList>{

    getTbName(): string {
        return "gamelist";
    }


    public afterDecode(): void {

    }
}

@tb_decoder(Tb_GameList)
export class Tb_GameListDecode implements ITbDecode<Tb_GameList>{
    async decode(container:TbContainer<Tb_GameList>) {
        return new Promise(async (r,j)=>{
            container.cfgs = []
            container.cfgMap.clear()
            let data:Asset =null
            if(GameCtx.ins.platform===Platform.web){//直接读本地
                data = await  ResManager.inst.loadBundleRes("resources/tb/gamelist",JsonAsset)
            
            }
            if(GameCtx.ins.platform===Platform.wechat){//读远程
    
            
            }
            //读取数据
            if(data instanceof JsonAsset){//json处理
                let list = data.json as Array<Tb_GameList>
                list.forEach(l=>{
                    container.cfgMap.set(l.id,l)
                    container.cfgs.push(l)
                })

                r(true)
                return
            }
        })

    }

}